package comnet.ftpserver;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.Socket;

/**
 * @author Mikko Puustinen (mikko.puustinen@gmail.com)
 * @version 0.1, 2007-dec-05
 */
public class FtpConnection {
    private Socket socket;
    DataInputStream remoteIn = null;
    DataOutputStream remoteOut = null;

    public FtpConnection(Socket socket) {
        this.socket = socket;
        try {
            remoteIn = new DataInputStream(socket.getInputStream());
            remoteOut = new DataOutputStream(socket.getOutputStream());
            System.out.println(remoteIn.readUTF());
            remoteOut.writeUTF("220 Tja");
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    public String[] getDirectories(File dir) {
        File[] files = dir.listFiles();
        if (files == null) {
            return null;
        }
        String[] temp = new String[files.length];

        for (int i = 0, j = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                temp[j++] = files[i].getName();
            }
        }

        return temp;
    }

    public String[] getFiles(File dir) {
        File[] files = dir.listFiles();
        if (files == null) {
            return null;
        }
        String[] temp = new String[files.length];

        for (int i = 0, j = 0; i < files.length; i++) {
            if (!files[i].isDirectory()) {
                temp[j++] = files[i].getName();
            }
        }

        return temp;
    }
}
